package com.bea.ftd.dashboard.validator;

import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class StringValidator {
	public static final String IP_REGEX = "(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])";

	public boolean isEmptyString(String str) {
		return StringUtils.isBlank(str);
	}

	/**
	 * 验证传入的字符串是否为合法ip
	 * 
	 * @param ip
	 * @return
	 */
	public boolean isValidIp(String ip) {

		if (null == ip) {
			return false;
		}

		return Pattern.matches(IP_REGEX, ip);
	}
}
